import { Group, Object3DEventMap, Vector3 } from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import qinoGlb from "@/assets/models/qino/qino.glb";
import { MyThings } from "@/interfaces/myThings.interface";
import { mainScene } from "../main.scene";

class QiNo implements MyThings {
  mesh: Group<Object3DEventMap>;
  loader: GLTFLoader;
  loaded: Promise<void>;
  constructor() {
    this.loader = new GLTFLoader();
    this.loaded = this.init();
  }
  async init() {
    const glb = await this.loader.loadAsync(qinoGlb);
    const mesh = glb.scene;
    console.log(mesh);
    mesh.name = "qino";
    mesh.castShadow = true;
    mesh.receiveShadow = true;
    mesh.position.set(-30, 0, 30);
    mesh.scale.multiplyScalar(.3); // 1为原来的1倍
    // mesh.rotation.y = Math.PI / 2;
    mesh.traverse(ele => {
      if (!ele.castShadow) {
        ele.castShadow = true;
        ele.receiveShadow = true;
      }
    });
    this.mesh = mesh;
  }
  gamepadUpdate([lh, lv, rh, rv]: number[], buttons: readonly GamepadButton[]) {
    // qino.mesh.translateX(-lh * 1);
    qino.mesh.translateZ(-lv * 1);
    qino.mesh.rotateOnAxis(new Vector3(0, 1, 0), -rh * Math.PI / 60);
  }
}

const qino = new QiNo();
export { qino };
